#include <stdio.h>
#include <sys/stat.h>
#include <errno.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>

#define PATH	"myfifo"

int  main(void)
{
	int fd;
	char str[255];

	//create fifo file
	if(mkfifo(PATH, 0666) < 0 && errno != EEXIST)
	{
		perror("create fifo failed");
		return -1;
	}
	else
	{
		printf("create fifo sucess\n");
		//open fifo file
		fd = open(PATH, O_CREAT | O_RDONLY, 0666);
		if(fd > 0)
		{
			//read content
			while(1)
			{
				read(fd, str, 255);
				printf("read : %s\n", str);
				close(fd);
			}
		}
		else
		{
			perror("open failed");
		}
	}
}
